package org.intrasearch.spider;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * PATISDG 10.11.2009
 */
public class VirtualFileFileImpl implements VirtualFile
{
    private final File file;

    VirtualFileFileImpl(File file)
    {
        this.file = file;
    }

    public VirtualFile[] listFiles()
    {
        VirtualFile[] files = new VirtualFile[file.listFiles().length];
        for (int i = 0; i < file.listFiles().length; i++)
        {
            files[i] = new VirtualFileFileImpl(file.listFiles()[i]);
        }
        return files;
    }

    public boolean isFile()
    {
        return file.isFile();
    }

    public String getName()
    {
        return file.getName();
    }

    public long length()
    {
        return file.length();
    }

    public boolean isDirectory()
    {
        return file.isDirectory();
    }

    public URL getURL()
    {
        try
        {
            return file.toURI().toURL();
        }
        catch (MalformedURLException e)
        {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String toString()
    {
        return file.getAbsolutePath();
    }
}
